//
//  AddMoRenPersonView.m
//  EnterpriseEdition
//
//  Created by ypj on 2021/10/9.
//

#import "AddMoRenPersonView.h"

@implementation  AddMoRenPersonView

- (void)awakeFromNib{
   [super awakeFromNib];
    self.backgroundColor = [UIColor clearColor];
    
    self.phoneTF.delegate = self;
    self.nameTF.delegate = self;
    [self.saveBtn addCorner:2];
    
  
}

- (IBAction)saveAction:(UIButton *)sender {
    if(self.nameTF.text.length == 0){
        showAlert(@"姓名不能为空");
        return;
    }
    if(self.phoneTF.text.length == 0){
        showAlert(@"电话不能为空");
        return;
    }
    if (![self.phoneTF.text isValidPhone]){
        showAlert(@"手机号码不正确");
        return;
    }
    if (self.currentValueBlock) {
        self.currentValueBlock(self.nameTF.text, self.phoneTF.text);
    }
    
}


+ (instancetype)shareInstance{
    return [[NSBundle mainBundle] loadNibNamed:kClsID(AddMoRenPersonView) owner:nil options:nil][0];
}


-(void)setDataWithName:(NSString*)name withPhoneString:(NSString*)phone{
    self.nameTF.text = name;
    self.phoneTF.text = phone;
}


-(void)textFieldDidChangeSelection:(UITextField *)textField
{
    if (textField == self.phoneTF){
        if (textField.text.length > 11) {
            textField.text = [textField.text substringToIndex:11];
        }
    }
    if (textField == self.nameTF){
        if (textField.text.length > 20) {
            textField.text = [textField.text substringToIndex:6];
        }
    }
}
@end
